/*
 * @Author: CPS
 * @Date: 2020-08-11 01:27:09
 * @Last Modified by:   CPS
 * @Last Modified time: 2020-08-11 16:48:53
 * @Projectname Electron-fileWatcher
 * @file_path D:\CPS\MyProject\Electron-fileWatcher\src\renderer\api\cevents.js
 * @Filename cevents.js
 */
'use strict'
/**
 * 判断是否 nodejs 环境
 *
 * @return     {boolean}  True if node, False otherwise.
 */
function isNode() {
  if (typeof window === 'undefined') {
    if (typeof global !== 'undefined' && global.hasOwnProperty('setImmediate')) {
      return true
    }
  }
  return false
}

class createNodeEvent {
  constructor() {
    this.event = null
  }
}

class createJsEvent {
  constructor(target) {
    this.target = target
    this.event = null
    this.data = {
      detail: {
        parm: 'test'
      }
    }

    return this
  }

  setTarget(target) {
    this.target = target
  }

  on(action, data) {


    this.actions[action] = this.event
  }

  send(action, data) {
    let event

    if (action) {
      event = new CustomEvent(action, data)
    } else {
      event = new Event(action)
    }

    this.dispatchEvent(event)

  }
}

class createCevent {
  constructor() {
    this.event = null

    switch (isNode()) {
      case true:
        // node 环境
        let events = require('events')
        this.event = new events.EventEmitter()
        break;
      default:
        // js 环境
        let event = 123
        break;
    }
  }
}

module.exports = createCevent

let t = new createCevent()

console.dir(t.event)